package com.cskaoyan.controller;

import com.cskaoyan.bean.PO.MarketBrand;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.AdminBrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:品牌制造商管理
 * @author:刘杰
 * @create: 2022-08-14 10:43
 */
@RestController
@RequestMapping("admin/brand")
public class AdminBrandController {
    @Autowired
    AdminBrandService adminBrandService;

    /**
     * 返回品牌商列表，根据id和name查询
     * @param id
     * @param name
     * @param info
     * @return
     */
    @RequiresPermissions("admin:brand:list")
    @RequestMapping("list")
    public BaseRespVo list(Integer id, String name, BasePageInfo info){
        CommonData list = adminBrandService.list(id,name,info);
        return BaseRespVo.ok(list);
    }

    /**
     * 修改品牌制造商
     * @param marketBrand
     * @return
     */
    @RequiresPermissions("admin:brand:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketBrand marketBrand){
        MarketBrand update = adminBrandService.update(marketBrand);
        return BaseRespVo.ok(update);
    }

    /**
     * 删除品牌制造商
     * @param marketBrand
     * @return
     */
    @RequiresPermissions("admin:brand:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketBrand marketBrand){
        adminBrandService.delete(marketBrand);
        return BaseRespVo.ok(null);
    }

    /**
     * 创建品牌制造商
     * @param marketBrand
     * @return
     */
    @RequiresPermissions("admin:brand:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketBrand marketBrand){
        MarketBrand create = adminBrandService.create(marketBrand);
        return BaseRespVo.ok(create);
    }
}
